import axios from "axios";

const service = axios.create({
    baseURL: "/api", // url = base url + request url
    withCredentials: true, // send cookies when cross-domain requests
    timeout: 50000, // request timeout
});

// request interceptor
service.interceptors.request.use(
    (config) => {
        return config;
    },
    (error) => {
        console.log(error); // for debug
        return Promise.reject(error);
    }
);

// 请求拦截器，内部根据返回值，重新组装，统一管理。
service.interceptors.response.use(
    (res) => {
        if (res.data.success) {
            return res;
        }
        return res;
    },
    (error) => {
        return Promise.reject(error);
    }
);

export default service;